(function() {
	$('#query_user').linkbutton({    
	    onClick: findUserInfo
	});
	 $('#add_user').linkbutton({    
	    onClick: addUser
	});
	$('#edit_user').linkbutton({    
	    onClick: editUser
	});
	$('#remove_user').linkbutton({    
	    onClick: removeUser
	});
	$('#updatePsw_user').linkbutton({    
	    onClick: updatePsw
	}); 
	
	$('#dataGrid_user').datagrid({
		url : "systemMaintenance/findUsers",
		toolbar : "#toolbar_user",
		rownumbers : true,
		singleSelect : true,
		fit : true,
		fitColumns : true,
		border : false,
		pageSize: 20,
		pagination: true,
		pageList:[20,30,50],
		onLoadError : errorPromt,
	    columns:[[
	    	{field:'fnetcasn',title:'CA序列号',width:100,align:'center'},
	    	{field:'fcode',title:'用户编号',width:100,align:'center'},
	        {field:'fname',title:'用户姓名',width:100,align:'center'},
	        {field:'fgroupname',title:'用户组',width:120,align:'center'},
	        {field:'ftypename',title:'用户类型',width:120,align:'center'},
	        /*{field:'fbqmc',title:'默认病区',width:120,align:'center'},*/
	        {field:'fksname',title:'默认科室',width:120,align:'center'},
	        {field:'ffzname',title:'病案室内部分组',width:120,align:'center'}
	    ]],
	    onLoadError : errorPromt
	});
	
	// CA序列号下拉框
	$('#caSN_user').combobox({
	    url:'systemMaintenance/findNetcaSN',
	    valueField:'FSERIALNUMBER',
	    textField:'FSERIALNUMBER',
	    formatter : function(row) {
			var s = '<span style="font-weight:bold">' + row.FSERIALNUMBER + '</span><br/>' +
            '<span style="color:#888">' + "工号："+row.FTYBH + '</span>';
            return s;
		},
		onLoadError : errorPromt
	});
	
	// 用户名下拉框
	$('#name_user').combobox({
	    url:'systemMaintenance/findUsername',
	    valueField:'ftygh',
	    textField:'fname',
	    formatter : function(row) {
			var s = '<span style="font-weight:bold">' + row.fname + '</span><br/>' +
            '<span style="color:#888">' + row.ftygh + '</span>';
            return s;
		},
		onChange : function(newValue, oldValue) {
			
			$.ajax({
				url: "systemMaintenance/findUserNum",
				type: 'get',
				data: {
					number: newValue
				},
				success: function(data) {
					if (data.length > 0) {
						$("#resName_user").textbox("setValue", data[0].fgh);
					}
				}
			})
		},
		onLoadError : errorPromt
	});
	
	// 角色下拉框
	$("#role_user").combobox({
		url : "systemMaintenance/findRoles",
		valueField : "fcode",
		textField : "fname"	,
		onLoadError : errorPromt
	});
	
	// 用户类型下拉框
	$("#userType_user").combobox({
		url : "systemMaintenance/findUserTypes",
		valueField : "fusertype",
		textField : "ftypename",
		panelHeight : 'auto',
		onSelect : function(record) {
			if (record.fusertype != "medicalRoom") {
				$("#groupBox_user").hide();
			} else if (record.fusertype == "medicalRoom") {
				$("#groupBox_user").show();
			}
		},
		onChange : function(newValue, oldValue) {
			if (newValue != "medicalRoom") {
				$("#groupBox_user").hide();
			} else if (newValue == "medicalRoom") {
				$("#groupBox_user").show();
			}
		},
		onLoadError : errorPromt
	});
	
	// 分组下拉框
	$("#group_user").combobox({
		url : "systemMaintenance/findGroups",
		valueField : "ffzbh",
		textField : "ffz",
		onLoadError : errorPromt
	});
	
	// 用户工作病区列表
	$("#district_tree_user").tree({
		url : "systemMaintenance/findDistricts",
		checkbox : true,
		onClick : function(node) {
			// 点击节点文本名时，实现选中或取消选中效果
			if (node.checkState == "checked") {
				$('#district_tree_user').tree('uncheck', node.target);
			} else {
				$('#district_tree_user').tree('check', node.target);
			}
		},
		onLoadError : errorPromt
	})
	
	// 用户工作科室下框
	$("#tree_user").tree({
		url : "systemMaintenance/findWorkRooms",
		checkbox : true,
		onClick : function(node) {
			// 点击节点文本名时，实现选中或取消选中效果
			if (node.checkState == "checked") {
				$('#tree_user').tree('uncheck', node.target);
			} else {
				$('#tree_user').tree('check', node.target);
			}
		},
		onLoadError : errorPromt
	})
	
	// 科室下拉框
	$("#depart_user").combobox({
		url : "systemMaintenance/findDepartments",
		valueField : "ftykh",
		textField : "fksname",
		onChange : function(newValue, oldValue) {
			var node = $('#tree_user').tree('find', newValue);
			if (node !=null && node != "") {
				$('#tree_user').tree('check', node.target);
			}
			
		},
		onLoadError : errorPromt
	});
	
	/*$("#district_user").combobox({
		url : "systemMaintenance/findDistrictList",
		valueField : "fbqdm",
		textField : "fbqmc",
		onChange : function(newValue, oldValue) {
			var node = $('#district_tree_user').tree('find', newValue);
			if (node !=null && node != "") {
				$('#district_tree_user').tree('check', node.target);
			}
			
		},
		onLoadError : errorPromt
	});*/
	
	
	// 查询条件栏默认科室下拉框
	$("#defaultDept_user").combobox({
		url : "systemMaintenance/findDepartments",
		valueField : "ftykh",
		textField : "fksname",
		panelHeight : '300',
		onLoadError : errorPromt
	})
	
	// 查询条件栏用户组下拉框
	$("#userGroup_user").combobox({
		url : "systemMaintenance/findRoles",
		valueField : "fcode",
		textField : "fname"	,
		panelHeight : '300',
		onLoadError : errorPromt
	})
	
	// 查询条件用户类型下拉框
	$("#type_user").combobox({
		url : "systemMaintenance/findUserTypes",
		valueField : "fusertype",
		textField : "ftypename",
		panelHeight : '100',
		onLoadError : errorPromt
	})
	
	// 查找用户信息
	function findUserInfo() {
		var nameNum = $("#userNum_user").val();  // 用户编号
		var name = $("#username_user").val();  // 用户名
		var department = $("#defaultDept_user").combobox("getValue");  // 默认科室
		var userGroup = $("#userGroup_user").combobox("getValue");  // 用户组
		var type = $("#type_user").combobox("getValue");  // 用户类型
		var casn = $("#netcaSN_user").val();  // 用户类型
		name = encodeURI(name);
		
		$('#dataGrid_user').datagrid({
			url : "systemMaintenance/findUsers",
			queryParams : {
				nameNum: nameNum,
				name: name,
				department: department,
				userGroup: userGroup,
				type: type,
				casn:casn
			},
			onLoadError : errorPromt
		});
		
	}

	// 添加用户信息
	function addUser() {
		// 清除表单中的原有数据
		$("#userForm_user").form("clear");
		// 显示密码框
		$("#userPsw_user").show();
		$("#tree_user").tree("reload");
		$("#district_tree_user").tree("reload");
		
		$('#dialog_user').dialog({
			title: '添加用户',
			closed: false,
			cache: false,
			buttons:[{
				text:'确定',
				handler:confirmAdd
			},{
				text:'取消',
				handler: function() {
					$("#dialog_user").dialog("close");
				}
			}]
		});
	}

	//确认新增
	function confirmAdd() {
		var nameNum = $("#name_user").combobox("getValue");
		var casn = $("#caSN_user").combobox("getValue");
		var name = $("#name_user").combobox("getText");
		var role = $("#role_user").combobox("getValue");
		var roleNumtext = $("#role_user").combobox("getText"); 
		var resName = $("#resName_user").val();
		var password = $("#psw_user").val();
		var userType = $("#userType_user").combobox("getValue");
		var userTypeText = $("#userType_user").combobox("getText");
		var departNum = $("#depart_user").combobox("getValue");
		var depart = $("#depart_user").combobox("getText");
		var groupNum = $("#group_user").combobox("getValue");
		var group = $("#group_user").combobox("getText");
		var phone = $("#phone_user").val();
	/*	var districtNum = $("#district_user").combobox("getValue");
		var district = $("#district_user").combobox("getText");*/
		var allData = $("#userType_user").combobox("getData"); //获取用户类型下拉菜单所有数据
		var alluserType = $("#role_user").combobox("getData"); //获取用户组下拉菜单所有数据
		var alldepart = $("#depart_user").combobox("getData"); //获取默认科室下拉菜单所有数据
		var mark = false;  // 默认科室是否包含在工作科室中标识符
		var checkNodes = $("#tree_user").tree("getChecked");
		var workrooms = "";  // 工作科室
		for (var i = 0; i < checkNodes.length; i++) {
	    	var code = checkNodes[i].id; // 被选中模块的编号
	    	if (null != code && "" != code) {
	    		workrooms += "\"" + checkNodes[i].id + "\",";
	    	}
	    	if (code == departNum) {
	    		mark = true;
	    	}
	    }
		workrooms = workrooms.slice(0, workrooms.length - 1);
		
		
		//var districtMark = false;  // 默认科室是否包含在工作科室中标识符
		var districtNodes = $("#district_tree_user").tree("getChecked");
		var districts = "";  // 工作科室
		for (var i = 0; i < districtNodes.length; i++) {
	    	var code = districtNodes[i].id; // 被选中模块的编号
	    	if (null != code && "" != code) {
	    		districts += "\"" + districtNodes[i].id + "\",";
	    	}
	    	/*if (code == districtNum) {
	    		districtMark = true;
	    	}*/
	    }
		districts = districts.slice(0, districts.length - 1);
		if (null == casn || "" == casn || null == casn || "" == casn) {
			$.messager.alert("警告", "CA序列号不能为空！", "info");
			return;
		}
		if (null == nameNum || "" == nameNum || null == name || "" == name) {
			$.messager.alert("警告", "姓名不能为空！", "info");
			return;
		}
		if (null == resName || "" == resName) {
			$.messager.alert("警告", "用户名不能为空！", "info");
			return;
		}
		if (null == role || "" == role) {
			$.messager.alert("警告", "角色不能为空！", "info");
			return;
		}
		if (null == password || "" == password) {
			$.messager.alert("警告", "密码不能为空！", "info");
			return;
		}
		if (null == userType || "" == userType) {
			$.messager.alert("警告", "用户类型不能为空！", "info");
			return;
		}
		/*if (null == districtNum || "" == districtNum) {
			$.messager.alert("警告", "默认病区不能为空！", "info");
			return;
		}*/
		if (null == departNum || "" == departNum) {
			$.messager.alert("警告", "默认科室不能为空！", "info");
			return;
		}
		if (null == workrooms || "" == workrooms) {
			$.messager.alert("警告", "工作科室不能为空！", "info");
			return;
		}
		if(containsCombo(userTypeText,allData) < 0){
			//用户类型输入框的验证。判断输入内容是否为下拉菜单中的内容
			$.messager.alert("警告", "非法用户类型，请重新输入！", "info");
			$("#userType_user").combobox("setText","");
			return;
		}else if(containsCombo(roleNumtext,alluserType) < 0){
			//用户组输入框的验证。判断输入内容是否为下拉菜单中的内容
			$.messager.alert("警告", "非法用户组，请重新输入！", "info");
			$("#role_user").combobox("setText","");
			return;
		}else if(containsCombo(depart,alldepart) < 0){
			//默认科室输入框的验证。判断输入内容是否为下拉菜单中的内容
			$.messager.alert("警告", "非法默认科室，请重新输入！", "info");
			$("#depart_user").combobox("setText","");
			return;
		}
	/*	if (null == districts || "" == districts) {
			$.messager.alert("警告", "工作病区不能为空！", "info");
			return;
		}*/
		/*if (null == phone || "" == phone) {
			$.messager.alert("警告", "手机号不能为空！", "info");
			return;
		}*/
		
		if(phone != null && phone != "") {
			if (regPhone(phone) ==false) {
				$.messager.alert("信息", "手机号码不合法，请重新输入!", "info");
				$("#phone_user").textbox("setValue","");
				return; 
			}
		}
		
		/*if (!districtMark) {
			$.messager.alert("信息", "工作病区应包含默认病区！", "info");
			return;
		}*/
		if (!mark) {
			$.messager.alert("信息", "工作科室应包含默认科室！", "info");
			return;
		}
		
		var result = checkUser(nameNum, resName);   // return标记，用来判断函数是否要中止
		// 当result为true时，中止函数执行
		if (result) {
			return;
		}
		
		$.ajax({
			url : "systemMaintenance/addUser",
			dataType:'json',
			type:'post',
			data:{
				casn:casn,
				nameNum : nameNum,
				name : name,
				role : role,
				resName : resName,
				password : password,
				userType : userType,
				departNum : departNum,
				depart : depart,
				groupNum : groupNum,
				group : group,
				phone : phone,
				workrooms : workrooms,
				districts : districts
				/*districtNum : districtNum,
				district : district,*/
			},
			success : function(data) {
				if (data.success == true) {
					$.messager.alert('信息', "添加成功！", 'info');
					$("#dialog_user").dialog("close");
					$("#dataGrid_user").datagrid("reload");
				}else{
					$.messager.alert('信息', data.msg, 'info');
				}
			},
			error : errorPromt
		});
	}

	// 修改用户信息
	function editUser() {
		// 隐藏密码框
		$("#userPsw_user").hide();
		var row = $("#dataGrid_user").datagrid("getSelected");
		if (row == "" || row == null) {
			$.messager.alert("信息","请选中用户信息！","info");
			return;
		}
		// 清除表单中的原有数据
		$("#userForm_user").form("clear");
		$("#userForm_user").form("load", row);  // 加载表单数据
		$("#tree_user").tree("reload");
		$("#district_tree_user").tree("reload");
		
		// 当用户名为sa时，设置用户名文本框为只读状态
		if (row.fcode == "sa") {
			$('#resName_user').textbox('readonly',true);
		} else {
			$('#resName_user').textbox('readonly',false);
		}
		
		// 勾选用户工作科室
		checkWorkRoom(row.fcode);
		
		// 勾选用户工作病区
		checkDistrict(row.fcode);
		
		$('#dialog_user').dialog({
			title: '修改用户信息',
			closed: false,
			cache: false,
			buttons:[{
				text:'确定',
				handler: confirmEdit
			},{
				text:'取消',
				handler:function(){
					$("#dialog_user").dialog("close");
				}
			}]
		});
	}

	//确认修改
	function confirmEdit() {
	    var row = $("#dataGrid_user").datagrid("getSelected");
		var id = row.fid;
		var name = $("#name_user").combobox("getText");  // 用户名
		var caSN = $("#caSN_user").combobox("getText");  // ca
		var nameNum = $("#name_user").combobox("getValue");  // 下拉框中用户名对应的用户编号
		var roleNum = $("#role_user").combobox("getValue");  // 下拉框中角色名对应的角色编号
		var roleNumtext = $("#role_user").combobox("getText");  // 下拉框中角色名
		var resName = $("#resName_user").val();
		var userType = $("#userType_user").combobox("getValue");
		var userTypename = $("#userType_user").combobox("getText");
		var departNum = $("#depart_user").combobox("getValue");
		var depart = $("#depart_user").combobox("getText");
		var groupNum = $("#group_user").combobox("getValue");
		var group = $("#group_user").combobox("getText");
		var phone = $("#phone_user").val();
		/*var districtNum = $("#district_user").combobox("getValue");
		var district = $("#district_user").combobox("getText");*/
		var allData = $("#userType_user").combobox("getData"); //获取用户类型下拉菜单所有数据
		var alluserType = $("#role_user").combobox("getData"); //获取用户组下拉菜单所有数据
		var alldepart = $("#depart_user").combobox("getData"); //获取默认科室下拉菜单所有数据
		
		var mark = false;   // 默认科室是否包含在工作科室中标识符
		var checkNodes = $("#tree_user").tree("getChecked");
		var workrooms = "";  // 工作科室
		for (var i = 0; i < checkNodes.length; i++) {
	    	var code = checkNodes[i].id; // 被选中模块的编号
	    	if (null != code && "" != code) {
	    		workrooms += "\"" + checkNodes[i].id + "\",";
	    	}
	    	if (code == departNum) {
	    		mark = true;
	    	}
	    }
		workrooms = workrooms.slice(0, workrooms.length - 1);
		if(containsCombo(userTypename,allData) < 0){
			//用户类型输入框的验证。判断输入内容是否为下拉菜单中的内容
			$.messager.alert("警告", "非法用户类型，请重新输入！", "info");
			$("#userType_user").combobox("setText","");
			return;
		}else if(containsCombo(roleNumtext,alluserType) < 0){
			//用户组输入框的验证。判断输入内容是否为下拉菜单中的内容
			$.messager.alert("警告", "非法用户组，请重新输入！", "info");
			$("#role_user").combobox("setText","");
			return;
		}else if(containsCombo(depart,alldepart) < 0){
			//默认科室输入框的验证。判断输入内容是否为下拉菜单中的内容
			$.messager.alert("警告", "非法默认科室，请重新输入！", "info");
			$("#depart_user").combobox("setText","");
			return;
		}
		
		//var districtMark = false;  // 默认科室是否包含在工作科室中标识符
		var districtNodes = $("#district_tree_user").tree("getChecked");
		var districts = "";  // 工作科室
		for (var i = 0; i < districtNodes.length; i++) {
	    	var code = districtNodes[i].id; // 被选中模块的编号
	    	if (null != code && "" != code) {
	    		districts += "\"" + districtNodes[i].id + "\",";
	    	}
	    	/*if (code == districtNum) {
	    		districtMark = true;
	    	}*/
	    }
		districts = districts.slice(0, districts.length - 1);
		
		if (null == caSN || "" == caSN) {
			$.messager.alert("警告", "CA序列号不能为空！", "info");
			return;
		}
		if (null == name || "" == name) {
			$.messager.alert("警告", "姓名不能为空！", "info");
			return;
		}
		if (null == roleNum || "" == roleNum) {
			$.messager.alert("警告", "角色不能为空！", "info");
			return;
		}
		if (null == resName || "" == resName) {
			$.messager.alert("警告", "用户名不能为空！", "info");
			return;
		}
		if (null == userType || "" == userType) {
			$.messager.alert("警告", "用户类型不能为空！", "info");
			return;
		}
		/*if (null == districtNum || "" == districtNum) {
			$.messager.alert("警告", "默认病区不能为空！", "info");
			return;
		}*/
		if (null == departNum || "" == departNum) {
			$.messager.alert("警告", "默认科室不能为空！", "info");
			return;
		}
		if (null == workrooms || "" == workrooms) {
			$.messager.alert("警告", "工作科室不能为空！", "info");
			return;
		}
		/*if (null == districts || "" == districts) {
			$.messager.alert("警告", "工作病区不能为空！", "info");
			return;
		}*/
		/*if (null == phone || "" == phone) {
			$.messager.alert("警告", "手机号不能为空！", "info");
			return;
		}*/
		if(phone != null && phone != "") {
			if (regPhone(phone) ==false) {
				$.messager.alert("信息", "手机号码不合法，请重新输入!", "info");
				$("#phone_user").textbox("setValue","");
				return; 
			}
		}
		/*if (!districtMark) {
			$.messager.alert("信息", "工作病区应包含默认病区！", "info");
			return;
		}*/
		if (!mark) {
			$.messager.alert("信息", "工作科室应包含默认科室！", "info");
			return;
		}
		
		var result = checkUser(nameNum, resName, id);   // return标记，用来判断函数是否要中止
		// 当result为true时，中止函数执行
		if (result) {
			return;
		}
		
		$.ajax({
			url : "systemMaintenance/updateUser",
			dataType:'json',
			type:'post',
			data:{
				id : id,
				caSN:caSN,
				nameNum : nameNum,
				name : name,
				roleNum : roleNum,
				resName : resName,
				userType : userType,
				departNum : departNum,
				depart : depart,
				groupNum : groupNum,
				group : group,
				phone : phone,
				workrooms : workrooms,
				districts : districts
				/*districtNum : districtNum,
				district : district*/
			},
			success : function(data) {
				if (data.success == true) {
					$.messager.alert('信息', "修改成功！", 'info');
					$("#dialog_user").dialog("close");
					$("#dataGrid_user").datagrid("reload");
				} else{
					$.messager.alert('信息', data.msg, 'info');
				}
			},
			error : errorPromt
		});
	}

	// 删除用户信息
	function removeUser() {
		var rows = $("#dataGrid_user").datagrid("getSelections");
		if (rows == null || "" == rows) {
			$.messager.alert("信息","请选中用户信息！","info");
			return;
		}
		
		for (var i = 0; i < rows.length; i++) {
			// 当用户名为sa时，不可删除
			if (rows[i].fcode == "sa") {
				$.messager.alert("信息","不能删除sa用户！","info");
				return;
			} 
		}
		
		$.messager.confirm('信息', '是否要删除用户信息?', function(r){
			if (r){
				var idStr = "";
				for (var i = 0; i < rows.length; i++) {
					idStr += rows[i].fid + ",";
				}
				
				$.ajax({
					url : "systemMaintenance/deleteUser",
					dataType:'json',
					type:'get',
					data:{
						idStr : idStr
					},
					success : function(data) {
						if (data.success == true) {
							$.messager.alert('信息', "删除成功！", 'info');
							$("#dataGrid_user").datagrid("reload");
						} 
					},error : errorPromt
				});
			} 
		});
	}

	// 修改用户密码
	function updatePsw() {
		var row = $("#dataGrid_user").datagrid("getSelected");
		if (row == "" || row == null) {
			$.messager.alert("信息","请选中用户信息！","info");
			return;
		}
		// 清除表单中的原有数据
		$("#pswForm_user").form("clear");
		
		$("#pswDialog_user").dialog({
			title: '修改用户密码',
			closed: false,
			cache: false,
			buttons:[{
				text:'确定',
				handler: confirmUpdate
			},{
				text:'取消',
				handler:function(){
					$("#pswDialog_user").dialog("close");
				}
			}]
		});
	}

	function confirmUpdate() {
		var row = $("#dataGrid_user").datagrid("getSelected");
		var id = row.fid;
		
		var newPsw = $("#newPsw_user").val();
		var confirmPsw = $("#confirmPsw_user").val();
		if (null == newPsw || "" == newPsw) {
			$.messager.alert("警告", "新密码不能为空！", "info");
			return;
		}
		if (null == confirmPsw || "" == confirmPsw) {
			$.messager.alert("警告", "确认密码不能为空！", "info");
			return;
		}
		if (newPsw != confirmPsw) {
			$.messager.alert("警告", "两次密码不一致！", "info");
			return;
		}
		
		$.ajax({
			url : "systemMaintenance/updatePassword",
			dataType:'json',
			type:'post',
			data:{
				id : id,
				newPsw : newPsw
			},
			success : function(data) {
				if (data.success == true) {
					$.messager.alert('信息', "密码更新成功！", 'info');
					$("#pswDialog_user").dialog("close");
				} 
			},
			error: function(xhr, status, error){
				$.messager.alert("信息", "密码更新失败！", "info");
			}
		});
	}

	// 校验用户信息
	function checkUser(nameNum, resName, id) {
	    var mark = false;  // return标记，用来判断调用该函数的函数是否要中止
		
		// 校验要新增用户的姓名、用户名是否已存在
		$.ajax({
			url : "systemMaintenance/getUsers",
			async : false,
			dataType: 'json',
			type: 'get',
			data: {id : id},
			success : function(data) {
	            for (var i = 0; i < data.length; i++) {
	            	// 判断注册用户名是否已存在
					if (data[i].fcode == resName) {
						$.messager.alert("警告", "该用户名已存在！", "info");
						mark = true;  // 用户名冲突时，将mark置为true，以使函数正确中止
						return;
					}
					// 判断用户的姓名是否已存在
					if (data[i].ftyyhbh == nameNum) {
						$.messager.alert("警告", "已为" + name + "注册过账号！", "info");
						mark = true;  // 姓名冲突时，将mark置为true，以使函数正确中止
						return;
					}
				}
			},
			error : errorPromt
		});
		
		return mark;
	}

	//勾选当前用户工作科室
	function checkWorkRoom(user) {
		$.ajax({
			url : 'systemMaintenance/findUserWorkRooms',
			type : 'get',
			dataType : 'json',
			cache : false,
			data : {
				user : user
			},
			success : function(data) {
				//if (data != null) {
					// 按模块默认选中已有菜单
					for (var i in data) {
						var node = $('#tree_user').tree('find', data[i].id);
						$('#tree_user').tree('check', node.target);
					}
				//}
			},
			error : errorPromt
		})
	}
	
	//勾选当前用户工作科室
	function checkDistrict(user) {
		$.ajax({
			url : 'systemMaintenance/findUserDistrict',
			type : 'get',
			dataType : 'json',
			cache : false,
			data : {
				user : user
			},
			success : function(data) {
				//if (data != null) {
					// 按模块默认选中已有菜单
					for (var i in data) {
						var node = $('#district_tree_user').tree('find', data[i].id);
						$('#district_tree_user').tree('check', node.target);
					}
				//}
			},
			error : errorPromt
		})
	}
})();